#include "wuMassiveManager.h"

wuMassiveManager::wuMassiveManager()
{

}

wuMassiveManager::~wuMassiveManager()
{
}

/*
void wuMassiveManager::setup(ofxBox2d * _box2d, int _vw, int _vh)
{
	wuBase2dManager::setup(_box2d, _vw, _vh);
}
*/
void wuMassiveManager::setPhysics(float _density, float _bounce, float _friction)
{
	density = _density;
	bounce = _bounce;
	friction = _friction;
}

void wuMassiveManager::addBitxo(ofImage *_skin, ofRectangle rect, vector <ofPoint> * _pts)
{
/*	ofxTriangle tri;
	tri.clear();
	tri.triangulate(*blob, tri_res);
*/
	wuMassive massive;
	massive.setup(box2d, _skin, rect, _pts);
//	massive.setup(box2d, _skin, rect, &((*blob).pts));
	massives.push_back(massive);
}
void wuMassiveManager::update()
{
        for (int i = 0; i < massives.size(); i++)
            massives[i].update();
}

void wuMassiveManager::draw(bool bDrawlines, int offX)
{
        for (int i = 0; i < massives.size(); i++)
            massives[i].draw(bDrawlines, offX);
}

void wuMassiveManager::drawSelected(bool bDrawlines, int offX)
{
    if(selection.width < vw || selection.height < vh)
    {

        for (int i = massives.size()-1; i >= 0; i--)
        {
            bool condi = (massives[i].getPosition().y > selection.y) && (massives[i].getPosition().y < selection.y + selection.height) &&
             (massives[i].getPosition().x > selection.x + x_scroll) && (massives[i].getPosition().x < selection.x + x_scroll + selection.width);

            if (condi)
                massives[i].draw(bDrawlines, offX);
        }
    }else
    {
        for (int i = 0; i < massives.size(); i++)
            massives[i].draw(bDrawlines, offX);
    }

}

void wuMassiveManager::clear()
{
    if(selection.width < vw || selection.height < vh)
    {

        for (int i = massives.size()-1; i >= 0; i--)
        {
            bool condi = (massives[i].getPosition().y > selection.y) && (massives[i].getPosition().y < selection.y + selection.height) &&
             (massives[i].getPosition().x > selection.x + x_scroll) && (massives[i].getPosition().x < selection.x + x_scroll + selection.width);

            if (condi)
            {
                massives[i].clear();
                massives.erase(massives.begin()+i);
            }
        }
    }else
    {
        for (int i = 0; i < massives.size(); i++)
            massives[i].clear();
        massives.clear();
    }

}

void wuMassiveManager::touch(int _x,int _y, int forceX, int forceY)
{
   for (int i = 0; i < massives.size(); i++)
		massives[i].touch(_x, _y, forceX, forceY);
}
